import json

import LLM


def accept_order(rider_info, step, money, order_info, now_location, positive_reviews_num, negative_reviews_num):
    info = {"now_location": now_location, "order_info": (order_info[2], order_info[3]), "order_money": money,
            "positive_reviews_num": positive_reviews_num, "negative_reviews_num": negative_reviews_num,
            "sex": rider_info["sex"], "diligent_level": rider_info["diligent_level"]}
    response = LLM.get_response_from_llm(3, info)
    print("llm接单结果为：" + response)
    reason = "none"
    ans = True
    try:
        response = json.loads(response)
        ans = response.get('ans')
    except Exception:
        print("LLM accept_order failed")

    try:
        reason = response.get("reason")
    except Exception:
        print("LLM accept_order reason log failed")

    id = rider_info["id"]
    print(id)
    path = f"./llm_agent_log/{id}_response_llm.txt"
    with open(path, 'a') as file:
        file.write("\n")
        file.write(f"-------------{step}--------------")
        file.write("\n")
        file.write("now_location: " + str(now_location))
        file.write("\n")
        file.write("order_info: " + str(order_info))
        file.write("\n")
        file.write("order_money: " + str(money))
        file.write("\n")
        file.write(str(ans))
        file.write("\n")
        file.write(reason)
        file.write("\n")
    return ans


if __name__ == "__main__":
    # test
    order_info = ('pickup', 3, 310, 131, 1, 6.103030407273376)
    now_location = [77, 71]
    rider_info = {'id': 0, 'sex': 0, "diligent_level": 10}
    accept_order(rider_info, 14, 10, order_info, now_location, 0, 0)
